import CryptoJs from 'crypto-js';
const APISecret = "ZTVlNGE2NmY4YzAwN2FkMGVlMzllODk2";
const APIKey = "87e0e75d48344d3248226c30f8a225ca";

export function generateAuthoriztion() {
  const date = new Date().toUTCString();
  const host = "iat-api.xfyun.cn";

  const signature_origin = `host: ${host}\ndate: ${date}\nGET /v2/iat HTTP/1.1`;
  const signature = CryptoJs.HmacSHA256(signature_origin, APISecret).toString(CryptoJs.enc.Base64);

  const authorization_origin = `api_key="${APIKey}", algorithm="hmac-sha256", headers="host date request-line", signature="${signature}"`;
  const wordArray = CryptoJs.enc.Utf8.parse(authorization_origin);
  const authorization = CryptoJs.enc.Base64.stringify(wordArray);

  return {
    authorization,
    date,
    host
  };
}